import { $ } from '../js/jquery-module.js';
import cookie from './library/cookie.js';
$(function() {
    $('header').load('./header_module-1.html');
    $('footer').load('./floor_module-1.html');
    let reg2 = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/;
    $('.toggle-way').click(function() {
        if ($('.toggle-way').text() == '短信验证码登录') {
            $('.toggle-way').text('密码登录');
            $('.user-data').html('<div class="phone e-mail"><span>中国+86<i></i></span><input type="tel" name="user_tel" placeholder="手机号"><span></span></div><div class="phone-code email-code"><input type="text" name="user_acode" placeholder="短信验证码"><button>获取验证码</button></div>');
            phoneEmail();
        } else {
            $('.toggle-way').text('短信验证码登录');
            $('.user-data').html('<input class="name" type="text" name="user_name" placeholder="手机号/邮箱地址/账户名"><div><input class="pw" type="password" name="user_pw" placeholder="密码"><i class="eye"></i></div>');
            phoneEmail();
        }
    })
    phoneEmail();

    function phoneEmail() {
        if ($('.phone>input').attr('placeholder') == "手机号") {
            $('.phone>input').keyup(function() {
                dispose(reg2, this);
            });
        }
    }
    /*可视/不可视 */
    $('.user-pw input').keyup(function() {
        if ($('.user-pw input').val()) {
            $('.eye').css('backgroundImage', 'url(../img/no-eye1.svg)');
        } else {
            $('.eye').css('backgroundImage', 'url(../img/no-eye.svg)');
        }
    })

    function dispose(elm, _this) {
        if (_this.value) {
            _this.value = _this.value.replace(/\s/g, '');
            let text = elm.test(_this.value) ? '' : '<i></i>手机号格式不正确';
            $(_this).next().html(text);
        } else {
            $(_this).next().html('');
        }
    }
    $('.eye').click(function() {
        setTimeout(function() {
            if ($('.user-pw input').val()) {
                if ($('.eye').css('backgroundImage') == 'url("http://localhost/lqf/www.huawei.com/src/img/no-eye1.svg")') {
                    $('.eye').css('backgroundImage', 'url(../img/eye.svg)');
                    $('.user-pw input').attr('type', 'text');
                } else {
                    $('.eye').css('backgroundImage', 'url(../img/no-eye1.svg)');
                    $('.user-pw input').attr('type', 'password');
                }
            }
        })
    })
})